import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './app.vue'
import {
  resolve
} from 'dns';

Vue.use(VueRouter)

const Routers = [
  {
    path: '/index',
    meta: {
      title: '首页',
    },
    component: (resolve) => require(['./views/index.vue'], resolve)
  },
  {
    path: '/about',
    meta: {
      title: '关于',
    },
    component: (resolve) => require(['./views/about.vue'], resolve)
  },
  {
    path: '/user/:id',
    meta: {
      title: '个人主页',
    },
    component: (resolve) => require(['./views/user.vue'], resolve)
  },
  {
    path: '/message',
    meta: {
      title: '消息',
    },
    component: (resolve) => require(['./views/message.vue'], resolve)
  },
  {
    path: '/*',
    redirect: '/index'
  }
]

const RouterConfig = {
  mode: 'hash',
  routes: Routers
  // ,
  // base: '/router/'
}

const router = new VueRouter(RouterConfig)

router.beforeEach( (to, from, next) => {
  window.document.title = to.meta.title
  next()
})

console.log(router.currentRoute)

new Vue({
  el: '#app',
  router: router,
  render: h => {
    return h(App)
  }
})